<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
    <script type="text/javascript" src="//api.map.baidu.com/api?v=3.0&ak=R0lg8GyKHQI6hUGCuS3OGGVNN3tWVAtN"></script>
    <style>
        html, body{ width: 100%; height: 100%; overflow: hidden; }
        .allMap{ width: 100%; height: 100%; }
    </style>
    <title>拱墅区教育地图</title>
</head>

<body>
    
    <div class="allMap" id="allMap"></div>
    <script>
        //初始化
        var map = new BMap.Map('allMap');

        //设置视角中心点
        map.centerAndZoom(new BMap.Point(120.155153,30.347163), 14);

        //启用滚轮放大缩小
        map.enableScrollWheelZoom();

        //设置地图样式
        map.setMapStyleV2({ 
            styleId: '44d85fb284e7907ae76f31be6a7847b3'
        });

        function getBoundary(){
            var bdary = new BMap.Boundary();
            var name = "拱墅区";

            //获取行政区域
            bdary.get(name, function(rs){
                var count = rs.boundaries.length;
                if (count === 0) {
                    alert('未能获取当前输入行政区域');
                    return ;
                }
                //-计算行政区域的点有多少个
                var pointArray = [];
                for(var i = 0; i < count; i++){
                    var ply = new BMap.Polygon(
                        rs.boundaries[i],
                        {
                            //--设置填充颜色
                            fillColor : "#000000",
                            //--设置填充透明度
                            fillOpacity : 0.2,
                            //--设置边线的粗细
                            strokeWeight : 2,
                            //--设置边线的透明度 0 - 1
                            strokeOpacity : 1,
                            //--设置边线样式为实线或虚线，取值 solid 或 dashed
                            strokeStyle : "solid",
                            //--设置边线颜色
                            strokeColor : "#df504c",    
                        }
                    );
                    //-添加覆盖物
                    map.addOverlay(ply);
                    pointArray = pointArray.concat(ply.getPath());
                }
                map.setViewport(pointArray);    //调整视野  
            });
        }

        setTimeout(function(){
            getBoundary();
        }, 2000);
    </script>
</body>

</html>